<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div, p {
            width: 300px;
            height: 30px;
            line-height: 30px;
            color: #fff;
            background-color: pink;
        }
    </style>
</head>
<body>
    <button>显示当前时间</button>
    <div>时间</div>
    <p>123</p>
    <script>
        //  innerText 不识别html标签
        // 1. 获取元素
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        // 2. 注册事件
        btn.onclick = function() {
            div.innerText = countDown();
        }

        function countDown() {
            var date = new Date(); // 当前时间

            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var dates = date.getDate();
            var day = date.getDay();
            return '今天是：' + year + '年' + month + '月' + day + '日';
        }
        // 元素可以不用添加事件
        var p = document.querySelector('p');
        p.innerText = countDown();
    </script>
</body>
</html>